<template>
  <div class="course-integral" v-if="credit_redeem && !$util.isEmpty(credit_arr)">
    <div class="title">积分抵扣</div>
    <div class="nub">
      <span class="font">可使用积分{{ credit_arr[0].credit }} ，本次使用</span>
      <el-select v-model="creditValue" placeholder="请选择" size="mini" @change="change" clearable>
        <el-option
          v-for="(item, index) in credit_arr"
          :key="index"
          :label="item.credit"
          :value="item.num"
        ></el-option>
      </el-select>
      <span class="text">抵扣</span>
      <span class="price">{{ creditValue || 0 | formatMoney }}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    credit_arr: {
      type: Array,
      default() {
        return []
      }
    },
    value: {
      type: Number,
      default: 0
    },
    credit_redeem: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      creditValue: ''
    }
  },
  watch: {
    value: {
      handler(val) {
        this.creditValue = val || ''
      },
      immediate: true
    }
  },
  methods: {
    change() {
      let obj = {}
      if (this.creditValue) {
        obj = this.credit_arr.find(item => item.num == this.creditValue)
      }
      this.$emit('change', obj)
    }
  }
}
</script>

<style lang="scss" scoped>
.course-integral {
  margin: 40px 30px 0;
  .title {
    font-size: 14px;
    font-family: SourceHanSansCN-Medium, SourceHanSansCN;
    font-weight: 500;
    color: $text-color-import;
  }
  .nub {
    margin-top: 15px;
    height: 45px;
    padding-left: 16px;
    padding-right: 30px;
    display: flex;
    align-items: center;
    background-color: #f6f9ff;
    .font {
      margin-right: 5px;
      font-size: 14px;
      font-family: SourceHanSansCN-Normal, SourceHanSansCN;
      font-weight: 400;
      color: $text-color-import;
    }
    .text {
      margin-left: auto;
      margin-right: 5px;
      font-size: 14px;
      font-family: SourceHanSansCN-Medium, SourceHanSansCN;
      font-weight: 500;
      color: $text-color-import;
    }
    .price {
      font-size: 14px;
      font-family: SourceHanSansCN-Medium, SourceHanSansCN;
      font-weight: 500;
      color: $text-color-price;
    }
    ::v-deep .el-input__inner {
      width: 100px;
      background-color: transparent;
    }
  }
}
</style>
